package java20190328;

public class TestDriver {

	public static void main(String[] args) {

		test01();

		test02();
	}

	/**
	 * 字符串工具类
	 */
	private static void test02() {
		// 创建一个StringBuilder
		StringBuilder sb = new StringBuilder();

		sb.append("小");
		sb.append("明");
		sb.append(",").append("小李");

		// 转换为字符串
		System.out.println("sb:::" + sb.toString());
	}

	/**
	 * 字符串初始化方式:内存存储方式
	 */
	private static void test01() {
		// 字符串常量赋值
		String str0 = "小明";
		String str1 = "小明";

		String str2 = new String("小明"); // 单独此行代码，在内存中创建了两个对象，一个在常量池汇中，一个在堆中
		String str3 = new String("小明");

		String str4 = "小" + "明"; // 字符串常量池栈中
		String str00 = "小";
		String str5 = str00 + "明"; // 堆中

		String str01 = str00.concat("");

		String str02 = str00.concat("明");

		// 进行 == 运算
		System.out.println("str0==str1:" + (str0 == str1)); // true
		System.out.println("str0==str2:" + (str0 == str2)); // false
		System.out.println("str2==str3:" + (str2 == str3)); // false
		System.out.println("str0==str4:" + (str0 == str4)); // true
		System.out.println("str2==str4:" + (str2 == str4)); // false
		System.out.println("str0==str5:" + (str0 == str5)); // false
		System.out.println("str2==str5:" + (str2 == str5)); // false

		System.out.println("str00==str01:" + (str00 == str01)); // true
		System.out.println("str0==str02:" + (str0 == str02)); // false
	}
}
